package org.zecontech.extraplus.init;

import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.zecontech.extraplus.ExtraPlus;
import org.zecontech.extraplus.util.Helpers;
import org.zecontech.extraplus.util.ItemUtils;

/**
 * 模组创造模式物品栏
 */
public class ModCreativeModeTabs {

    // 物品栏总线
    public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS =
            DeferredRegister.create(Registries.CREATIVE_MODE_TAB, ExtraPlus.MOD_ID);

    // 注册杂项物品栏
    public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXTRA_PLUS_MISC =
            CREATIVE_MODE_TABS.register("extra_plus_misc", () -> CreativeModeTab.builder().title(Component.translatable("itemGroup.extraplus.misc")).icon(
            () -> ModItems.KELONG.get().getDefaultInstance()).displayItems((parameters, output) -> {
                ModItems.ITEMS.getEntries().forEach(item -> {
                    if (!Helpers.getItemName(item.get()).contains("potted")
                            && !ItemUtils.isTools(item.get())
                            && !ItemUtils.isArmor(item.get())
                            && !ItemUtils.isEdible(item.get())) {
                        output.accept(item.get());
                    }
                });
            }).build());

    // 注册工具物品栏
    public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXTRA_PLUS_TOOLS =
            CREATIVE_MODE_TABS.register("extra_plus_tools", () -> CreativeModeTab.builder().title(Component.translatable("itemGroup.extraplus.tools")).icon(
                    () -> ModItems.AMBER_PICKAXE.get().getDefaultInstance()).displayItems((parameters, output) -> {
                ModItems.ITEMS.getEntries().forEach(item -> {
                    if (ItemUtils.isTools(item.get()) && !ItemUtils.isSword(item.get())) {
                        output.accept(item.get());
                    }
                });
                    }).build());

    // 注册战斗物品栏
    public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXTRA_PLUS_COMBAT =
            CREATIVE_MODE_TABS.register("extra_plus_combat", () -> CreativeModeTab.builder().title(Component.translatable("itemGroup.extraplus.combat")).icon(
                    () -> ModItems.AMBER_SWORD.get().getDefaultInstance()).displayItems((parameters, output) -> {
                ModItems.ITEMS.getEntries().forEach(item -> {
                    if (ItemUtils.isArmor(item.get())) {
                        output.accept(item.get());
                    } else if (ItemUtils.isSword(item.get())) {
                        output.accept(item.get());
                    }
                });
            }).build());

    // 注册食物物品栏
    public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXTRA_PLUS_FOOD =
            CREATIVE_MODE_TABS.register("extra_plus_food", () -> CreativeModeTab.builder().title(Component.translatable("itemGroup.extraplus.food")).icon(
                    () -> ModItems.FRIED_EGG.get().getDefaultInstance()).displayItems((parameters, output) -> {
                ModItems.ITEMS.getEntries().forEach(item -> {
                    if (ItemUtils.isEdible(item.get())) {
                        output.accept(item.get());
                    }
                });
            }).build());
}
